package ui;

import java.awt.Font;
import java.util.List;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;

import obj.Path;

public class DashBord extends JPanel {
	VehicleReportPanel vReport;

	public DashBord() {

		JPanel panelSpeedChart = new SpeedChart();
		panelSpeedChart.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));

		JPanel panelVehicleCount = new JPanel();
		vReport = new VehicleReportPanel();
		panelVehicleCount.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JPanel vehicleQueuePanel = new JPanel();
		vehicleQueuePanel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(panelVehicleCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(vehicleQueuePanel, GroupLayout.PREFERRED_SIZE, 574, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(panelSpeedChart, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(panelVehicleCount, GroupLayout.PREFERRED_SIZE, 257, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(vehicleQueuePanel, GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE))
						.addComponent(panelSpeedChart, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		
		JLabel lblVehicleInQueue = new JLabel("Vehicle in Queue");
		lblVehicleInQueue.setFont(new Font("Serif", Font.BOLD, 16));
		
		VehicleQueueReportPanel vQueueReport = new VehicleQueueReportPanel();
		GroupLayout gl_vehicleQueuePanel = new GroupLayout(vehicleQueuePanel);
		gl_vehicleQueuePanel.setHorizontalGroup(
			gl_vehicleQueuePanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_vehicleQueuePanel.createSequentialGroup()
					.addGroup(gl_vehicleQueuePanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_vehicleQueuePanel.createSequentialGroup()
							.addGap(230)
							.addComponent(lblVehicleInQueue))
						.addGroup(gl_vehicleQueuePanel.createSequentialGroup()
							.addContainerGap()
							.addComponent(vQueueReport, GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)))
					.addContainerGap())
		);
		gl_vehicleQueuePanel.setVerticalGroup(
			gl_vehicleQueuePanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_vehicleQueuePanel.createSequentialGroup()
					.addGap(5)
					.addComponent(lblVehicleInQueue)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(vQueueReport, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
					.addContainerGap())
		);
		vehicleQueuePanel.setLayout(gl_vehicleQueuePanel);
		
		JLabel lblVehicleStatistics = new JLabel("Vehicle Statistics");
		lblVehicleStatistics.setFont(new Font("Serif", Font.BOLD, 16));
		GroupLayout gl_panelVehicleCount = new GroupLayout(panelVehicleCount);
		gl_panelVehicleCount.setHorizontalGroup(
			gl_panelVehicleCount.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panelVehicleCount.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panelVehicleCount.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panelVehicleCount.createSequentialGroup()
							.addComponent(vReport, GroupLayout.DEFAULT_SIZE, 637, Short.MAX_VALUE)
							.addContainerGap())
						.addGroup(gl_panelVehicleCount.createSequentialGroup()
							.addGap(297)
							.addComponent(lblVehicleStatistics, GroupLayout.PREFERRED_SIZE, 171, GroupLayout.PREFERRED_SIZE)
							.addGap(181))))
		);
		gl_panelVehicleCount.setVerticalGroup(
			gl_panelVehicleCount.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelVehicleCount.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblVehicleStatistics)
					.addGap(18)
					.addComponent(vReport, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panelVehicleCount.setLayout(gl_panelVehicleCount);

		JLabel lblSpeedChart = new JLabel("Speed Chart");
		lblSpeedChart.setFont(new Font("Serif", Font.BOLD, 16));

		JLabel lblKmph = new JLabel("(kmph)");
		GroupLayout gl_panelSpeedChart = new GroupLayout(panelSpeedChart);
		gl_panelSpeedChart.setHorizontalGroup(gl_panelSpeedChart.createParallelGroup(Alignment.LEADING).addGroup(
				gl_panelSpeedChart
						.createSequentialGroup()
						.addGroup(
								gl_panelSpeedChart
										.createParallelGroup(Alignment.LEADING)
										.addGroup(
												gl_panelSpeedChart.createSequentialGroup().addGap(31)
														.addComponent(lblSpeedChart))
										.addGroup(
												gl_panelSpeedChart.createSequentialGroup().addGap(61)
														.addComponent(lblKmph))).addContainerGap(48, Short.MAX_VALUE)));
		gl_panelSpeedChart.setVerticalGroup(gl_panelSpeedChart.createParallelGroup(Alignment.LEADING).addGroup(
				gl_panelSpeedChart.createSequentialGroup().addContainerGap().addComponent(lblSpeedChart)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(lblKmph)
						.addContainerGap(251, Short.MAX_VALUE)));
		panelSpeedChart.setLayout(gl_panelSpeedChart);
		setLayout(groupLayout);
	}

	private static final long serialVersionUID = -1670886465560929323L;

	public void drawTable(List<Path> pList) {
		vReport.drawTable(pList);
	}
}
